﻿using System;
using WordContentControl = Microsoft.Office.Interop.Word.ContentControl;
using WordDocument = Microsoft.Office.Interop.Word.Document;

namespace CodeCounsel.Office.DatabindingToolkit
{
    public class Document
    {
        WordDocument _wordDocument = null;
        CustomXmlPartCollection _xmlParts = null;
        ContentControlCollection _contentControls = null;
        public bool ShowBuiltInXmlParts { get; set; }

        internal WordDocument WordDocument
        {
            get { return _wordDocument; }
        }

        public CustomXmlPartCollection XmlParts
        {
            get { return _xmlParts; }
        }

        public ContentControlCollection ContentControls
        {
            get { return _contentControls; }
        }

        public Document(WordDocument wordDocument)
        {
            ShowBuiltInXmlParts = false;
            _wordDocument = wordDocument;
            _xmlParts = new CustomXmlPartCollection(this, _wordDocument.CustomXMLParts);
            _contentControls = new ContentControlCollection(
                _wordDocument, _wordDocument.ContentControls);
        }

        internal string InsertControl(
            Microsoft.Office.Interop.Word.WdContentControlType wdContentControlType)
        {
            object range = (object)_wordDocument.Application.Selection.Range;
            WordContentControl control = _wordDocument.ContentControls.Add(wdContentControlType,
                ref range);
            return control.ID;
        }
    }
}
